<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px">
      <el-form-item label="评估记录编号" prop="code">
        <el-input v-model="queryParams.code" clearable></el-input>
      </el-form-item>
      <el-form-item label="评估记录名称" prop="name">
        <el-input v-model="queryParams.name" clearable></el-input>
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button plain @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="Plus" @click="newAssess">新建评估</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" ref="tableRef" :data="dataList" stripe>
      <el-table-column label="序号" type="index" align="center" width="55" />
      <el-table-column label="评估记录编号" prop="code" align="center" />
      <el-table-column label="评估记录名称" prop="name" align="center" />
      <el-table-column :label="listSourceField[type]" prop="dataSource" align="center"></el-table-column>
      <el-table-column label="地震输入方式" prop="seismicInput" align="center"></el-table-column>
      <el-table-column label="评估描述" prop="info" align="center" />
      <el-table-column label="创建单位" prop="orgName" align="center" />
      <el-table-column label="创建人" prop="userName" align="center" />
      <el-table-column label="操作" align="center">
        <template #default="{ row }">
          <el-button type="text" @click="assess(row.id)">评估</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination style="margin-top: 15px" v-show="queryParams.total > 0" :total="queryParams.total"
      v-model:page="queryParams.page" v-model:limit="queryParams.rows" @pagination="getList" ref="pagination" />
  </div>
</template>
<script setup name="seismic">
import { getPage } from '@/api/lifelineProject/index'
import { listSourceField } from '@/views/lifelineProject/index'

const props = defineProps({
  open: Boolean,
  url: String,
  type: String
})
const emits = defineEmits(['update:open'])
const { proxy } = getCurrentInstance()

const queryParams = ref({
  page: 1,
  rows: 10,
  total: 0
})
const loading = ref(false)
const dataList = ref([])

const getList = () => {
  loading.value = true
  getPage(props.url, queryParams.value).then(res => {
    loading.value = false
    dataList.value = res.data?.rows
    queryParams.value.total = res.data?.total
  })
}
// 查询
const handleQuery = () => {
  getList()
}

// 重置
const resetQuery = () => {
  proxy.resetForm('queryRef')
  queryParams.value.page = 1
  handleQuery()
}

// 新建评估
const newAssess = () => {
  emits('update:open', true)
  proxy.$Bus.emit('clearForm')
}

proxy.$Bus.on('update-list', () => {
  getList()
})

// 评估
const assess = (id) => {
  emits('update:open', true)
  proxy.$Bus.emit('getDetail', { url: props.url, id })
}

onMounted(() => {
  getList()
})

onBeforeUnmount(() => {
  proxy.$Bus.all.clear()
})
</script>
<style scoped></style>